package day06;

import java.util.Scanner;

/**
 * 需求:<<主持人大赛>>有N位评委给选手打分
 *       选手的最终得分为:去掉最高分和最低分之后的N-2位评委的平均分
 */
public class CalTotalAvgDemo {
    public static void main(String[] args) {
        double[] arr = getScore(5);
        double avg = getAvg(arr);
        System.out.println("最终得分："+avg);


    }

    public static double[] getScore(int n) {
        double[] arrScore = new double[n];
        Scanner scanner = new Scanner(System.in);

        for (int i = 0; i < n; i++) {
            System.out.println("第" + (i + 1) + "位");
            arrScore[i] = scanner.nextDouble();
        }
        return arrScore;
    }

    public static double getAvg(double[] arr) {
        double average = 0.0;
        double total = 0.0;
        double min=arr[0];
        double max=arr[0];
        for (int i = 0; i < arr.length; i++) {
            total +=arr[i];
            if(min>arr[i]){
                min = arr[i];
            }
            if(max<arr[i]){
                max=arr[i];
            }

        }
        average = (total-min-max)/(arr.length-2);
        return average;

    }
}
